/*
 * UDPThread.h
 *
 *  Created on: 18.03.2011
 *      Author: niea
 */


#pragma once

#include <cerrno>
#include <cstring>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include <arpa/inet.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <string>
#include "../common/log.hpp"
#include "../common/Settings.hpp"

// for pthreads
#define _REENTRANT

namespace efs
{

class UDPThread
{
public:
	UDPThread(Settings const& settings);
	virtual ~UDPThread();
	bool start();
	void stop();

protected:

	pthread_t m_thread;
	Settings m_settings;
	int m_socket;
	struct sockaddr_in m_sockaddr;
	bool m_stop_req;

	void printError(std::string func_name) const;
	static void * threadProcStarter(void *base_class_pointer);
	virtual void threadProc() = 0;
	bool prepareSocket();
	void closeAll();
};

}
